package com.example.wm_mbp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.wm_mbp.common.R;
import com.example.wm_mbp.model.Category;
import com.example.wm_mbp.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * ClassName: CategoryController
 * Package: com.example.wm_mbp.controller
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-03-15
 * Time: 23:17
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //GET
    //http://localhost:8080/category/page?page=1&pageSize=10
    //菜品分类管理
    @GetMapping("/page")
    public R category(Integer page,Integer pageSize){
        Page<Category> page1 = new Page<>(page,pageSize);

        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(Category::getId);

        categoryService.page(page1,queryWrapper);

        return R.success(page1);
    }

    //PUT
    //	http://localhost:8080/category
    //菜品修改
    //参数 {"id":1397844263642378200,"name":"湘菜","sort":"2"}
    @PutMapping()
    public R upload(@RequestBody Category category){

        //每一个管理 都涉及到 多个字段 可以统一处理 增加修改
        categoryService.saveOrUpdate(category);

        return R.success("修改成功");
    }


}
